package com.sxbbc.plat.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.function.common.GetRest;
import com.function.common.RestResponse;
import com.sxbbc.common.basics.exceptions.ThrowJsonException;
import com.sxbbc.common.basics.utils.calculation.CalcuUtils;
import com.sxbbc.common.basics.utils.statics.StaticUtils;
import com.sxbbc.common.core.entity.jz.BBusiness;
import com.sxbbc.common.core.service.BBusinessService;

/**
 * 商家业务
 *
 * @author Wahyee
 */
@Service
public class BusinessService {

    @Autowired
    public BBusinessService bBusinessService;

    /**
     * 处理商家申请审核
     *
     * @param business
     * @return
     * @author Wahyee
     */
    public RestResponse handleBusinessApplyStatus(BBusiness business) {
        CalcuUtils calUtil = CalcuUtils.getInstance();
        boolean save = bBusinessService.updateById(business);
        if (!save) {
            throw new ThrowJsonException("平台处理商家状态失败");
        }
        //审核商家的线上或线下的状态为通过时，进入此方法
        if (calUtil.isEquals(business.getStatus(), StaticUtils.STATUS_SUCCESS)
                || calUtil.isEquals(business.getOfflineStatus(), StaticUtils.STATUS_SUCCESS)) {
            BBusiness bBusiness = bBusinessService.getById(business.getId());
            if (!calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_NO)
                    && calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_NO)) {
                //线上不为0 线下为0 进入方法
                bBusinessService.handleApplySuccessAddBLogin(bBusiness);
            } else if (calUtil.isEquals(bBusiness.getStatus(), StaticUtils.STATUS_NO)
                    && !calUtil.isEquals(bBusiness.getOfflineStatus(), StaticUtils.STATUS_NO)) {
                //线上为0 线下不为0 进入方法
                bBusinessService.handleApplySuccessAddBLogin(bBusiness);
            }
        }
        return GetRest.getSuccess("处理成功");
    }
}
